Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DraftEditor crashes in Safari when IME composition committed #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

taylrj
Copy link

@taylrj taylrj commented Jun 26, 2021

Summary

When typing using IME at the end of a composition, draft-js will do
a full rerender. Which is done by changing the key of DraftEditor component.
If we change the key of a react component, the component itself
will not remount, but any children inside this component will do.
Therefore, children are unmounted and mounted again, which causes editor
crash issue in Safari. Since React reconciliation fail to diff previous DOM
and current DOM due to some of them are considered as 'not-existing'
which can not be removed by the reconsiliation process.

Since this patch, key of existing block won't change hence its children won't remount.

Test Plan

Open a file in example folder (e.g. media.html).
Make sure the draft editor won't crash after a IME composition is committed, especially in Safari.

@taylrj taylrj added the bug Something isn't working label Jun 26, 2021
@taylrj taylrj requested a review from babygoat June 26, 2021 10:18
@taylrj taylrj self-assigned this Jun 26, 2021
@taylrj taylrj force-pushed the fix/restore-dom branch from f6257e3 to 4a6f309 Compare June 26, 2021 13:19
@babygoat
Copy link

Could u elaborate more on why the issue is platform dependent?

@@ -192,7 +192,6 @@ class DraftEditorContents extends React.Component<Props> {
preventScroll,
selection,
tree: editorState.getBlockTree(key),
key: `${key}-${blockKeyMap.get(key) || '0'}`,
Copy link

@babygoat babygoat Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the key removal have any side-effect on the parent block of the <Component /> ?

Copy link
Author

@taylrj taylrj Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it won't.
React uses key to identify the existing element which won't be unmounted. Also, an element and its descendants won't be unmounted only if its type (e.g. div, span) and key keep the same with the previous one. If an element with no key, React only compares its type and index(index in a children list).

Since is the only child of its parent Child, this diff removes the key from here to its parent which I don't think has any side-effect, AFAIK.

taylrj added 2 commits June 30, 2021 09:27
When typing using IME at the end of a composition, draft-js will do
a full rerender. Which is done by changing the key of DraftEditor component.
If we change the key of a react component, the component itself
will not remount, but any children inside this component will do.
Therefore, children are unmounted and mounted again, which causes editor
crash issue in Safari. Since React reconciliation fail to diff previous DOM
and current DOM due to some of them are considered as 'not-existing'
which can not be removed by the reconsiliation process.

Since this patch, key of existing block won't change hence its children won't remount.
@taylrj taylrj force-pushed the fix/restore-dom branch from 4a6f309 to fb563a6 Compare June 30, 2021 01:28
@babygoat
Copy link

babygoat commented Jul 6, 2021

Do we want to use this patch for the upcoming release? i.e. Drop the v0.11.8-rc.2

@babygoat
Copy link

babygoat commented Jul 6, 2021

If yes, I would have to downgrade the package version back to v0.11.8-rc.1 on @twreporter/keystone

@taylrj
Copy link
Author

taylrj commented Jul 6, 2021

No, this patch is not ready to be shipped.

Please downgrade package version back to v0.11.8-rc.0 (without this patch) on @twreporter/keystone.

@taylrj taylrj added the help wanted Extra attention is needed label Jul 7, 2021
@babygoat
Copy link

babygoat commented Jul 8, 2021

No, this patch is not ready to be shipped.

Please downgrade package version back to v0.11.8-rc.0 (without this patch) on @twreporter/keystone.

Would we want to use a stable version(v0.11.8) on @twreporter/keystone or just keep it on rc version?

@taylrj
Copy link
Author

taylrj commented Jul 8, 2021

I wouldn't say it is a stable version since we still have an unresolved Safari issue in this PR base on the above comment :

Could u elaborate more on why the issue is platform dependent?

As a public package which claims to support Safari in latest 2 versions, I'd like to bump to v0.11.8 when current issue has been resolved.

If no further concerns, please just keep it on rc version in the upcoming release.

babygoat added a commit to babygoat/keystone that referenced this pull request Jul 9, 2021
This patch downgrades the package for since twreporter/draft-js#2 is not
yet for release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants